public class Board {
    private char[][] board;

    public Board() {
        board = new char[3][3];
        reset();
    }

    public void reset() {
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                board[i][j] = ' ';
    }

    // 判断该点位能否下棋
    public boolean makeMove(Move move, char symbol) {
        if (board[move.row][move.col] == ' ') {
            board[move.row][move.col] = symbol;
            return true;
        }
        return false;
    }

    // 获胜条件 一行一列或斜对角
    public boolean checkWin(char symbol) {
        for (int i = 0; i < 3; i++) {
            if (board[i][0] == symbol && board[i][1] == symbol && board[i][2] == symbol) return true;
            if (board[0][i] == symbol && board[1][i] == symbol && board[2][i] == symbol) return true;
        }
        return (board[0][0] == symbol && board[1][1] == symbol && board[2][2] == symbol)
            || (board[0][2] == symbol && board[1][1] == symbol && board[2][0] == symbol);
    }


    // 棋盘是否被塞满
    public boolean isFull() {
        for (char[] row : board)
            for (char cell : row)
                if (cell == ' ') return false;
        return true;
    }

    // 不用管，已经做了ui界面
    // public void printBoard() {
    //     System.out.println("-------------");
    //     for (int i = 0; i < 3; i++) {
    //         System.out.print("| ");
    //         for (int j = 0; j < 3; j++) {
    //             System.out.print(board[i][j] + " | ");
    //         }
    //         System.out.println();
    //         System.out.println("-------------");
    //     }
    // }

    // 更新棋盘
    public char[][] getBoard() {
        return board;
    }
}